using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class ButtonChooseMap : MonoBehaviour
{
	public string key;

	public int price;

	public GameObject panelBlock;

	public Text txtPrice;

	public Text txtName;

	private bool unlocked;

	public Image imgMap;

	public int indexMap;

	public void _Start()
	{
		unlocked = ((PlayerPrefs.GetInt(key + "unlocked") != 0) ? true : false);
		panelBlock.SetActive(!unlocked);
		txtName.text = key;
		txtPrice.text = string.Concat(price);
	}

	public void clickUnlock()
	{
		if (!unlocked)
		{
			if (CoinManager.CheckBuy(price))
			{
				PlayerPrefs.SetInt(key + "unlocked", 1);
				CoinManager.coin -= price;
				CoinManager.UpCoin();
				unlocked = true;
				panelBlock.SetActive(!unlocked);
				DataManager.Instance.AddMaps(1);
				Object.FindObjectOfType<SoundMusicManager>().Unlockmap();
				UnityEngine.Debug.Log("Unlock Map!");
                //FirebaseStat.Instance.LogNormalEvent("ns_unlock_level", "level_id", (indexMap + 1).ToString());
                if (!AdManager1.instance.ShieldAddress) AdManager.single.ShowNative();
            }
			else
			{
				UnityEngine.Debug.Log("Not Enough Coins");
			}
		}
	}

	public void clickChooseMap()
	{
		if (unlocked)
		{
			StartManager.Instance.fadeScipt.showFade();
			BadLogic.nameMap = indexMap;
			StartCoroutine(delayLoadScene());
			UnityEngine.Debug.Log("Click ChooseMap");
            if (!AdManager1.instance.ShieldAddress) AdManager.single.ShowNative();
		}
	}

	public void SetImageMap(Sprite spr)
	{
		imgMap.sprite = spr;
	}

	private IEnumerator delayLoadScene()
	{
		yield return new WaitForSecondsRealtime(0.5f);
		SceneManager.LoadScene("Main");
	}

	public int CheckStatus()
	{
		int result = 0;
		if (!unlocked)
		{
			if (CoinManager.CheckBuy(price))
			{
				result = 1;
			}
		}
		else
		{
			result = 0;
		}
		return result;
	}
}
